package zyn_hy_login;

public class DB_conn
{
	private String connString;
	private String dbTable;
	private String folderImg;
	private String img;
	private String mailatt;
	private String mailcontent;
	private String mailtitle;
	private String proEdit;
	private String proNew;
	private String proRead;
	private String tableName;
	private String tableType;

	public DB_conn()
	{
	}

	public DB_conn(String strConnId)
	{
		DataRow row = DBCommon.getDataBySqluniquetempvar.Tables[0].Rows[0];
		this.connString = "";
		this.connString = this.connString + "server=" + row.getItem("x1").toString().trim();
		this.connString = this.connString + ";database=" + row.getItem("x2").toString().trim();
		this.connString = this.connString + ";User ID=" + row.getItem("x3").toString().trim();
		this.connString = this.connString + ";Password=" + row.getItem("x4").toString().trim();
		this.dbTable = row.getItem("x5").toString().trim();
		this.img = row.getItem("x7").toString().trim();
		this.tableName = row.getItem("name").toString().trim();
		this.tableType = row.getItem("x6").toString().trim();
		this.folderImg = row.getItem("x8").toString().trim();
		this.proNew = row.getItem("x9").toString().trim();
		this.proEdit = row.getItem("x10").toString().trim();
		this.proRead = row.getItem("x11").toString().trim();
		this.mailtitle = row.getItem("x13").toString().trim();
		this.mailcontent = row.getItem("x14").toString().trim();
		this.mailatt = row.getItem("x15").toString().trim();
	}

	public final void CreateConnString(String strConnId)
	{
		DataRow row = DBCommon.getDataBySqluniquetempvar.Tables[0].Rows[0];
		this.connString = "";
		this.connString = this.connString + "server=" + row.getItem("x1").toString().trim();
		this.connString = this.connString + ";database=" + row.getItem("x2").toString().trim();
		this.connString = this.connString + ";User ID=" + row.getItem("x3").toString().trim();
		this.connString = this.connString + ";Password=" + row.getItem("x4").toString().trim();
		this.dbTable = row.getItem("x5").toString().trim();
		this.img = row.getItem("x7").toString().trim();
		this.tableName = row.getItem("name").toString().trim();
		this.tableType = row.getItem("x6").toString().trim();
		this.folderImg = row.getItem("x8").toString().trim();
		this.proNew = row.getItem("x9").toString().trim();
		this.proEdit = row.getItem("x10").toString().trim();
		this.proRead = row.getItem("x11").toString().trim();
		this.mailtitle = row.getItem("x13").toString().trim();
		this.mailcontent = row.getItem("x14").toString().trim();
		this.mailatt = row.getItem("x15").toString().trim();
	}

	public final void excuteParamSql(String strSql, SqlParameter[] sqlparams)
	{
		SqlConnection connection = new SqlConnection();
		connection.ConnectionString = this.connString;
		SqlCommand command = new SqlCommand();
		command.CommandType = CommandType.Text;
		command.CommandText = strSql;
		command.Connection = connection;
		for (SqlParameter parameter : sqlparams)
		{
			command.Parameters.Add(parameter);
		}
		connection.Open();
		command.ExecuteNonQuery();
		connection.Close();
	}

	public final void excuteSql(String strSql)
	{
		SqlConnection connection = new SqlConnection();
		connection.ConnectionString = this.connString;
		SqlCommand command = new SqlCommand();
		command.CommandType = CommandType.Text;
		command.CommandText = strSql;
		command.Connection = connection;
		connection.Open();
		command.ExecuteNonQuery();
		connection.Close();
	}

	public final int excuteSqlCount(String strSql)
	{
		SqlConnection connection = new SqlConnection();
		connection.ConnectionString = this.connString;
		SqlCommand command = new SqlCommand();
		command.CommandType = CommandType.Text;
		command.CommandText = strSql;
		command.Connection = connection;
		SqlDataAdapter adapter = new SqlDataAdapter();
		adapter.SelectCommand = command;
		DataSet dataSet = new DataSet();
		adapter.Fill(dataSet);
		int count = dataSet.Tables[0].Rows.size();
		dataSet.Clear();
		connection.Close();
		return count;
	}

	public final DataSet getDataBySql(String strSql)
	{
		SqlConnection connection = new SqlConnection();
		connection.ConnectionString = this.connString;
		SqlCommand command = new SqlCommand();
		command.CommandType = CommandType.Text;
		command.CommandText = strSql;
		command.Connection = connection;
		SqlDataAdapter adapter = new SqlDataAdapter();
		adapter.SelectCommand = command;
		DataSet dataSet = new DataSet();
		adapter.Fill(dataSet);
		return dataSet;
	}

	public final SqlDataReader getDataReadBySql(String strSql)
	{
		SqlConnection connection = new SqlConnection();
		connection.ConnectionString = this.connString;
		SqlCommand command = new SqlCommand();
		command.CommandType = CommandType.Text;
		command.CommandText = strSql;
		command.Connection = connection;
		connection.Open();
		return command.ExecuteReader(CommandBehavior.CloseConnection);
	}

	public final int getMaxId()
	{
		String strSql = "select isnull(max(id),0) from " + this.dbTable;
		DataSet set = this.getDataBySql(strSql);
		if (set.Tables[0].Rows.size() == 0)
		{
			return 0;
		}
		return (int) set.Tables[0].Rows[0][0];
	}

	public final int getNameCount(String pid, String cname, String ztType, String ztValue)
	{
		String strSql = " select id from " + this.getDbTable() + " where name='" + cname + "'";
		if (ztType.equals("1"))
		{
			strSql = strSql + " and zt='" + ztValue + "' ";
		}
		else if (ztType.equals("2"))
		{
			strSql = strSql + " and zt<>'" + ztValue + "' ";
		}
		strSql = strSql + " and id2=" + pid;
		return this.excuteSqlCount(strSql);
	}

	public final boolean TestConn()
	{
		try
		{
			SqlConnection connection = new SqlConnection(this.connString);
			connection.Open();
			connection.Close();
		}
		catch (java.lang.Exception e)
		{
			return false;
		}
		return true;
	}

	public final String getConnString()
	{
		return this.connString;
	}
	public final void setConnString(String value)
	{
		this.connString = value;
	}

	public final String getDbTable()
	{
		return this.dbTable;
	}
	public final void setDbTable(String value)
	{
		this.dbTable = value;
	}

	public final String getFolderImg()
	{
		return this.folderImg;
	}
	public final void setFolderImg(String value)
	{
		this.folderImg = value;
	}

	public final String getImg()
	{
		return this.img;
	}

	public final String getMailatt()
	{
		return this.mailatt;
	}
	public final void setMailatt(String value)
	{
		this.mailatt = value;
	}

	public final String getMailcontent()
	{
		return this.mailcontent;
	}
	public final void setMailcontent(String value)
	{
		this.mailcontent = value;
	}

	public final String getMailtitle()
	{
		return this.mailtitle;
	}
	public final void setMailtitle(String value)
	{
		this.mailtitle = value;
	}

	public final String getProEdit()
	{
		return this.proEdit;
	}
	public final void setProEdit(String value)
	{
		this.proEdit = value;
	}

	public final String getProNew()
	{
		return this.proNew;
	}
	public final void setProNew(String value)
	{
		this.proNew = value;
	}

	public final String getProRead()
	{
		return this.proRead;
	}
	public final void setProRead(String value)
	{
		this.proRead = value;
	}

	public final String getTableName()
	{
		return this.tableName;
	}
	public final void setTableName(String value)
	{
		this.tableName = value;
	}

	public final String getTableType()
	{
		return this.tableType;
	}
	public final void setTableType(String value)
	{
		this.tableType = value;
	}
}